Skip to content

fix(core): add real-world time budget to prevent infinite-loop event-driven agent state transitions#28389

Open
mahendrarathore1742 wants to merge 1 commit into
google-gemini:mainfrom
mahendrarathore1742:fix/infinite-loop-event-driven-agent-loop
Open

fix(core): add real-world time budget to prevent infinite-loop event-driven agent state transitions#28389
mahendrarathore1742 wants to merge 1 commit into
google-gemini:mainfrom
mahendrarathore1742:fix/infinite-loop-event-driven-agent-loop

Conversation

@mahendrarathore1742

Copy link
Copy Markdown
  • Added a shared deadline to sendMessageStream and processTurn
  • Passed the deadline through recursive continuation and loop recovery paths
  • Enforced a real-world time budget before and during event stream iteration
  • Prevents zero-latency async event flooding from bypassing MAX_TURNS
  • Keeps existing turn-based protections while adding robust time-based safety

close #28271

@mahendrarathore1742 mahendrarathore1742 requested a review from a team as a code owner July 13, 2026 09:20
@github-actions github-actions Bot added the size/s A small PR label Jul 13, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 32
  • Additions: +32
  • Deletions: -0
  • Files changed: 1

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a real-world time budget mechanism to GeminiClient to prevent zero-latency event flooding by propagating a deadline across stream-generation methods. If the deadline is exceeded, a LoopDetected event is yielded. The feedback points out that the default time budget of 5 seconds is too short for typical agent tasks (such as LLM generation or tool execution) and suggests increasing it to 5 minutes to prevent premature aborts.

Comment on lines +80 to +81
// Real-world time budget (ms) to protect against zero-latency event flooding
const DEFAULT_TIME_BUDGET_MS = 5000;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The default time budget of 5000ms (5 seconds) is extremely short for real-world agent executions. A single LLM generation or tool execution (e.g., running a build or test) can easily exceed 5 seconds, causing the agent to prematurely abort with a LoopDetected event. Consider increasing this default significantly (e.g., to 5 minutes / 300,000ms) to ensure robust execution of non-trivial tasks.

Suggested change
// Real-world time budget (ms) to protect against zero-latency event flooding
const DEFAULT_TIME_BUDGET_MS = 5000;
// Real-world time budget (ms) to protect against zero-latency event flooding
const DEFAULT_TIME_BUDGET_MS = 300000;

@gemini-cli gemini-cli Bot added priority/p1 Important and should be addressed in the near term. area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality priority/p1 Important and should be addressed in the near term. size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite Loop Vulnerability in Event-Driven Agent State Transition

1 participant